package org.personal.init;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.myhibernate.ProxyTemplate;
import org.myhibernate.Template;
import org.personal.Constants;
import org.personal.entity.Layout;
import org.personal.entity.Page;
import org.personal.entity.Portlet;

public class InitData 
{
//	public static void main(String[] args) 
//	{
//		
//		System.out.println("finish");
//	}
	public void init()
	{
		Template<Page> templatePage=new ProxyTemplate(Page.class).getInstance();
		Template<Layout> templateLayout=new ProxyTemplate(Layout.class).getInstance();
		Template<Portlet> templatePortlet=new ProxyTemplate(Portlet.class).getInstance();
		try 
		{
			List<Portlet> portlets=new ArrayList<Portlet>();
			Portlet portlet=null;
			portlet=new Portlet();
			portlet.setTitle("指南");
			portlet.setPagePath("/WEB-INF/portlet/GuidPortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			portlet=new Portlet();
			portlet.setTitle("新闻");
			portlet.setPagePath("/WEB-INF/portlet/NewsPortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			portlet=new Portlet();
			portlet.setTitle("通知");
			portlet.setPagePath("/WEB-INF/portlet/NoticePortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			portlet=new Portlet();
			portlet.setTitle("报纸");
			portlet.setPagePath("/WEB-INF/portlet/PaperPortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			portlet=new Portlet();
			portlet.setTitle("图片");
			portlet.setPagePath("/WEB-INF/portlet/PicturePortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			portlet=new Portlet();
			portlet.setTitle("产品");
			portlet.setPagePath("/WEB-INF/portlet/ProductPortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			portlet=new Portlet();
			portlet.setTitle("报表");
			portlet.setPagePath("/WEB-INF/portlet/ReportPortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			portlet=new Portlet();
			portlet.setTitle("手册");
			portlet.setPagePath("/WEB-INF/portlet/ShoucePortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			portlet=new Portlet();
			portlet.setTitle("学习园地");
			portlet.setPagePath("/WEB-INF/portlet/StudyPortlet.jsp");
			portlet.getEditUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ALLUSER);
			portlet.getUsers().add(Constants.USER_ANONYMOUS);
			portlets.add(portlet);
			
			templatePortlet.save(portlets);
			
			
			List<Layout> layouts=new LinkedList<Layout>();
			Layout layout=null;
			layout=new Layout();
			layout.setTitle("1行2列");
			layout.setPagePath("/WEB-INF/layout/1row2column.jsp");
			layouts.add(layout);
			
			layout=new Layout();
			layout.setTitle("2列");
			layout.setPagePath("/WEB-INF/layout/2column.jsp");
			layouts.add(layout);
			
			layout=new Layout();
			layout.setTitle("3列");
			layout.setDefaultLayout(true);
			layout.setPagePath("/WEB-INF/layout/3column.jsp");
			layouts.add(layout);
			
			layout=new Layout();
			layout.setTitle("4列");
			layout.setPagePath("/WEB-INF/layout/4column.jsp");
			layouts.add(layout);
			
			templateLayout.save(layouts);
			
			
			Page page=new Page();
			page.setTitle("Demo页面");
			page.setPagePath("/WEB-INF/jsp/html/wuchuan/demopage.jsp");
			page.getEditUsers().add(Constants.USER_ALLUSER);
			page.getUsers().add(Constants.USER_ALLUSER);
			page.getUsers().add(Constants.USER_ANONYMOUS);
			page.setLayout(3);
			page.getPortlets().add("0:0:1");
			page.getPortlets().add("0:1:2");
			page.getPortlets().add("1:0:3");
			page.getPortlets().add("1:1:4");
			page.getPortlets().add("2:0:5");
			page.getPortlets().add("2:1:6");
			templatePage.save(page);
			
			
		} catch (Exception e) 
		{
			e.printStackTrace();
		}finally
		{
			templatePage.close();
			templateLayout.close();
			templatePortlet.close();
			
		}
	}
}
